﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BookShop;
using SubSonic;

public partial class UserControl_Login : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LoginImageButton_Click(object sender, ImageClickEventArgs e)
    {
        System.Web.Security.FormsAuthentication.SignOut();
        Session.Abandon();
    }
    protected void userLogin_Authenticate(object sender, AuthenticateEventArgs e)
    {
        e.Authenticated = Membership.ValidateUser(userLogin.UserName, userLogin.Password);
        if (e.Authenticated)
        {
            FormsAuthentication.SetAuthCookie(userLogin.UserName, userLogin.RememberMeSet);
            MembershipUser msu = Membership.GetUser(userLogin.UserName);
            Session["UserName"] = userLogin.UserName;
            string storeId = new Select(Employee.StoreIDColumn).From<Employee>().Where(Employee.UserNameColumn).IsEqualTo(userLogin.UserName).ExecuteScalar().ToString().Trim();
            ProfileCommon pf = Profile.GetProfile(userLogin.UserName);
            pf.UserName = userLogin.UserName;
            pf.StoreId = storeId;
            pf.Save();
        }
    }
}
